<?php

namespace app\admin\controller;

use Couchbase\UserSettings;
use think\Controller;
use think\Db;
use think\Request;

class Con3 extends AdminController
{
    // 加载权限列表页面，遍历数据
    public function func1()
    {
        $list = Db::table('node')->select(); // 从数据库中查询数据
        return view('admin@con3/func1',['list'=>$list]);
    }


    // 加载权限添加页面
    public function func2()
    {
        return view('admin@con3/func2');
    }

    // 加载权限修改页面，查询数据库，遍历数据
    public function edit($n_id)
    {
        $list = Db::table('node')->find($n_id);
        return view('admin@con3/edit',['list'=>$list]);
    }


    // 添加权限
    public function doadd()
    {
        $p = input('post.');
        if (empty($p['n_nodename']) || empty($p['n_controlname']) || empty($p['n_modelname'])){
            return $this->error('请将内容填写完整!');
        }
        $data = [
            'n_nodename' => $p['n_nodename'],
            'n_controlname' => $p['n_controlname'],
            'n_modelname' => $p['n_modelname']
        ];
        $result = Db::table('node')->data($data)->insert();
        if ($result>0){
            return $this->success('添加成功！','admin/Con3/func1');
        } else {
            return $this->error('添加失败！');
        }
    }

    // 修改权限数据
    public function doedit(Request $request,$n_id)
    {
        $info = $request->put();
        $data = [
            'n_nodename' => $info['n_nodename'],
            'n_controlname' => $info['n_controlname'],
            'n_modelname' => $info['n_modelname']
        ];
        $result = Db::table('node')->where('n_id',$n_id)->update($data);
        if ($result > 0) {
            return $this->success('更新成功!', url('admin/Con3/func1'));
        } else {
            return $this->error('更新失败!');
        }
    }
}